export class Enemy {
  constructor(
    public name: string,
    public maxHealth: number,
    public attack: number,
    public defense: number,
    public experienceReward: number
  ) {
    this.currentHealth = maxHealth;
  }

  public currentHealth: number;

  // 显示状态
  displayStatus(): void {
    console.log(`${this.name} (等级 ${this.calculateLevel()}):`);
    console.log(`生命值: ${this.currentHealth}/${this.maxHealth}`);
    console.log(`攻击力: ${this.attack}`);
    console.log(`防御力: ${this.defense}`);
    console.log(`经验值奖励: ${this.experienceReward}`);
  }

  // 攻击方法
  attackHero(hero: any): void {
    const damage = Math.max(1, this.attack - hero.defense);
    hero.takeDamage(damage);
    console.log(`${this.name} 攻击了 ${hero.name}，造成 ${damage} 点伤害！`);
  }

  // 受到伤害
  takeDamage(damage: number): void {
    const actualDamage = Math.max(1, damage - this.defense);
    this.currentHealth -= actualDamage;
    if (this.currentHealth < 0) this.currentHealth = 0;
    console.log(`${this.name} 受到了 ${actualDamage} 点伤害！`);
  }

  // 判断是否存活
  isAlive(): boolean {
    return this.currentHealth > 0;
  }

  // 计算敌人等级（基于属性）
  calculateLevel(): number {
    const totalPower = this.maxHealth + this.attack + this.defense;
    return Math.floor(totalPower / 30) + 1;
  }
}